package com.spzx.channel.controller;

import com.spzx.channel.domain.ItemVo;
import com.spzx.channel.service.ItemService;
import com.spzx.common.core.web.controller.BaseController;
import com.spzx.common.core.web.domain.AjaxResult;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.redisson.api.RBloomFilter;
import org.redisson.api.RedissonClient;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@Tag(name = "商品详情接口")
@RestController
@RequestMapping("/item")
public class ItemController extends BaseController {

    @Autowired
    private ItemService itemService;
    @Autowired
    private StringRedisTemplate redisTemplate;
    @Autowired
    private RedissonClient redissonClient;

    //商品详情
    @Operation(summary = "商品详情")
    @GetMapping("/{skuId}")
    public AjaxResult item(@PathVariable Long skuId){

        RBloomFilter<Object> bloomFilter = redissonClient.getBloomFilter("sku:bloom:filter");
        boolean isExist = bloomFilter.contains(skuId);
        if(isExist){
            ItemVo itemVo = itemService.item(skuId);
            return success(itemVo);
        }else{
            return warn("你查询商品不存在");
        }


//        Boolean isExist = redisTemplate.opsForValue().getBit("sku:bitmap:filter", skuId);
//        if(Boolean.TRUE.equals(isExist)){
//            ItemVo itemVo = itemService.item(skuId);
//            return success(itemVo);
//        }else{
//            return warn("你查询商品不存在");
//        }
    }
}
